import math
import time

import pymysql
import uuid
import datetime
import hashlib
import json
def get_db_connection(data):
    connection = pymysql.connect(
        host=data.get("host"),
        user=data.get("user"),
        password=data.get("password"),
        database=data.get("database"),
        cursorclass=pymysql.cursors.DictCursor
    )
    return connection

def getUuid():
    return uuid.uuid4()

def md5_salted(string):
    salt = "random_salt_value"
    # 将原始字符串和盐值拼接
    string_with_salt = (string + salt).encode('utf - 8')
    md5 = hashlib.md5()
    md5.update(string_with_salt)
    return md5.hexdigest()

def getFormatted_datetime_now():
    now = datetime.datetime.now()
    formatted_datetime = now.strftime('%Y-%m-%d %H:%M:%S')
    return formatted_datetime

def getseconds_time(total_seconds):
    total_seconds = int(total_seconds)
    minutes = total_seconds // 60
    seconds = total_seconds % 60
    formatted_time = f"{minutes}:{seconds:02d}"
    return formatted_time


def check_local_time_exceed_60_seconds(start_time):
    """
    检查本地时间是否超过60秒

    :return: 如果超过60秒返回True，否则返回False
    """
    # 这里可以添加一些代码逻辑，模拟程序运行一段时间，比如睡眠30秒
    start_time = float(start_time)
    # 获取当前本地时间的时间戳（再次获取）
    end_time = time.time()

    # 计算时间差（以秒为单位）
    elapsed_time = end_time - start_time

    if elapsed_time > 60:
        return True, math.ceil(abs(end_time - start_time))
    else:
        return False, math.ceil(abs(end_time - start_time))

if __name__ == '__main__':
    print(time.time())
    a, b = check_local_time_exceed_60_seconds(float("1731065561.8201725"))
    print(a)
    print(b)